package com.sky.controller.admin;
import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController(value = "AdminOrderController")
@Slf4j
@Api(tags = "管理订单相关接口")
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    private OrderService orderService;
    /**
     * 搜索订单
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("搜索订单")
    //get请求不用加requestBody
    public Result<PageResult> search(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("要搜索的订单的条件信息:{}", ordersPageQueryDTO);
        PageResult pageResult=orderService.search(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 查看订单详情
     * @param id
     * @return
     */
    @GetMapping("details/{id}")
    @ApiOperation("查看订单详情")
    public Result<OrderVO> details(@PathVariable Long id) {
        log.info("用户的订单id：");
        OrderVO orderVO=orderService.details(id);
        return Result.success(orderVO);
    }

    /**
     * 接单
     * @param
     * @return
     */
    @PutMapping("confirm")
    @ApiOperation("接单")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        log.info("用户的订单id：");
        orderService.confirm(ordersConfirmDTO.getId());
        return Result.success();
    }

    /**
     * 派送订单
     * @param id
     * @return
     */
    @PutMapping("delivery/{id}")
    @ApiOperation("派送订单")
    public Result delivery(@PathVariable Long id) {
        log.info("用户的订单id：");
        orderService.delivery(id);
        return Result.success();
    }

    /**
     * 用户下单后拒绝订单
     * @param ordersRejectionDTO
     * @return
     */
    @PutMapping("rejection")
    @ApiOperation("拒单")
    public Result reject(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        log.info("拒单：{}"+ordersRejectionDTO);
        orderService.reject(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 用户完成订单
     * @param id
     * @return
     */
    @PutMapping("complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable Long id) {
        log.info("订单：{}已完成",id);
        orderService.complete(id);
        return Result.success();
    }

    /**
     * 取消订单
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        log.info("去掉订单：{}",ordersCancelDTO);
        orderService.cancle(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 统计各个状态的订单数
     * @return
     */
    @GetMapping("statistics")
    @ApiOperation("各个状态的订单数")
    public Result<OrderStatisticsVO> statistics() {
        OrderStatisticsVO orderStatisticsVO=orderService.statistics();
        return Result.success(orderStatisticsVO);
    }
}
